/**
 * 是否禁用
 * @param {Function}
 * 禁用： <div v-disabled="true">导入工程</div>
 * 不禁用： <div v-disabled="false">导入工程</div>
 */
export const disabled = {
  bind(el, { value }, vnode) {
    el.disableFn = e => { e.stopPropagation();e.preventDefault()}
    el.handler = val => {
      if (['INPUT', 'BUTTON', 'SELECT'].includes(el.tagName)) { el.disabled = val }
      if(val) {
        el.classList.add('disabled') // 可选：添加禁用样式
        el.addEventListener('click', el.disableFn, true)
      } else {
        el.classList.remove('disabled')
        el.removeEventListener('click', el.disableFn, true)
      }
    }
    el.handler(value)
  },
  update(el, {value}, vnode) {
    el.handler(value)
  },
  unbind(el) {
    el.classList.remove('disabled')
    el.removeEventListener('click', el.disableFn, true)
  },
};
